<template>
	<view>
		<u--form labelPosition="left" :model="model1" :rules="rules" ref="form1">
			<h1 style="margin-left: 40%;">预约</h1>
			<u-form-item label="会员id" prop="userInfo.name" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.memberId" border="none"></u--input>
			</u-form-item>
			<u-form-item label="预约日期" prop="userInfo.name" borderBottom ref="item1" @click="time">
				{{model1.userInfo.orderDate}}
				<u-calendar :show="show" :mode="mode" @confirm="confirm"></u-calendar>
			</u-form-item>
			<u-form-item label="预约类型" prop="userInfo.orderType" borderBottom @click="showSex = true; " ref="item1">
				<u--input v-model="model1.userInfo.orderType" disabled disabledColor="#ffffff" placeholder="请选择预约类型"
					border="none"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="套餐id" prop="userInfo.setmealId" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.setmealId" border="none"></u--input>
			</u-form-item>
			<u-form-item label="" prop="userInfo.setmealId" borderBottom ref="item1">
				<u-button type="primary" text="确定预约" @tap="submitBtn"></u-button>
			</u-form-item>
		</u--form>
		<u-action-sheet :show="showSex" :actions="actions" title="请选择预约类型" description="如果选择保密会报错"
			@close="showSex = false" @select="sexSelect">
		</u-action-sheet>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orders: [],
				show: false,
				mode: 'single',
				showSex: false,
				model1: {
					userInfo: {},
				},
				actions: [{
						name: '电话预约',
					},
					{
						name: '微信预约',
					},
					{
						name: '保密',
					},
				],
				rules: {
					'userInfo.name': {
						type: 'string',
						required: true,
						message: '请填写会员id',
						trigger: ['blur', 'change']
					},
					'userInfo.orderType': {
						type: 'string',
						max: 1,
						required: true,
						message: '请选择预约类型',
						trigger: ['blur', 'change']
					},
				},
				radio: '',
				switchVal: false
			}
		},
		methods: {
			time() {
				this.show = true
			},
			confirm(e) {
				console.log(e);
				console.log(e.toString().split("'")[0])
				this.model1.userInfo.orderDate = e.toString().split("'")[0]
				this.show = false
			},
			sexSelect(e) {
				this.model1.userInfo.orderType = e.name
				this.$refs.form1.validateField('userInfo.orderType')
			},
			submitBtn() {
				console.log(this.model1.userInfo.memberId)
				console.log(this.model1.userInfo.orderDate)
				console.log(this.model1.userInfo.orderType)
				console.log(this.model1.userInfo.setmealId)
				console.log(this.model1.userInfo)
				this.orders.memberId = this.model1.userInfo.memberId
				// this.orders.orderDate = this.model1.userInfo.orderDate
				this.orders.orderType = this.model1.userInfo.orderType
				this.orders.setmealId = this.model1.userInfo.setmealId
				console.log(this.orders)
				
				uni.request({
					url: "http://127.0.0.1:9900/api/orders",
					method:'POST',
					data: {
						orders:this.orders,
					},
					success: (res) => {
						console.log(res)
					},
					
				});
				// u.request({
				// 	url: "http://127.0.0.1:9900/api/orders",
				// 	method: "POST",
				// 	header: {
				// 		"content-type":'application/json;charset=UTF-8'
				// 	},
				// 	data: {
				// 		orders: this.orders
				// 	},

				// 	success(res) {
				// 		console.log(res)

				// 	}
				// })
			}
		},
	};
</script>
